package com.dingup.provider.controller.dingtalk;

import com.dingup.api.Util.RedisUtils;
import com.dingup.api.base.HttpResContent;
import com.dingup.api.bean.response.ResponseSelectBean;
import com.dingup.api.model.sys.SysUser;
import com.dingup.api.template.message.auth.AuthHelper;
import com.dingup.api.template.message.bean.DingTalkConfig;
import com.suyeer.basic.util.BHttpResUtil;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.List;

import static com.dingup.api.base.BaseUtil.saveErrorMsgAndData;
import static com.dingup.api.base.BaseUtil.saveSuccessMsgAndData;

/**
 * Created by wancheng on 2018/9/3.
 */
@Controller
@RequestMapping("/dingtalk")
public class DingtalkController {

    @RequestMapping(value = "/get_dingtalk_config.do",method = RequestMethod.POST)
    public void getStudent(HttpServletRequest request,
                           HttpServletResponse response,
                           String url) {
        HttpResContent<DingTalkConfig> hrc = new HttpResContent<>(request, response);
        hrc.setFuncDes("钉钉js鉴权");
        try {
            DingTalkConfig config = AuthHelper.getConfig(url);
            saveSuccessMsgAndData(hrc, config);
        } catch (Exception e) {
            saveErrorMsgAndData(hrc, e);
        } finally {
            BHttpResUtil.writeResult(hrc, true);
        }
    }
}
